/**
*	流程模块：流程步骤flowtcourse的扩展js
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-20
*/

js.flowcourse_input = function(){
	
	
	this.initbodys = function(){
		if(this.isedit){
			var o1 = this.form('where');
			o1.value= jm.base64decode(o1.value);
		}
	}
	
	this.onsubmitbefore = function(d){
		if(d.fmodeid=='0')return '请先选择模块';
		return {
			where:jm.base64encode(d.where)
		}
	}
	
	
}

js.flowcourse_xiang = function(){
	
	
	this.initbodys = function(){
		this.data['where'] = jm.base64decode(this.data['where']);
	}
}


js.flowcourse_list = function(){
	var me 		= this;
	this.fmodeid = '0';
	
	this.initbodys = function(){
		this.settable({
			urlparams:{fmodeid:'0'}
		});
		this.addlefthtml('<select style="width:180px" class="input" id="fmodeid_'+this.rand+'"><option value="0">-选择模块-</option></select>');
		$('#fmodeid_'+this.rand+'').change(function(){
			me.listobj.changemodeid(this);
		});
		if(this.iscompany){
			this.setcolumns('cid',{
				hidden:true
			});
			this.optobj.addbtn('匹配流程','pipei', this);
		}
	}
	
	this.onloadbefore=function(d){
		var arr = d.modearr,type,i,len;
		if(arr){
			var barr = {},sda=[];
			len = arr.length;
			for(i=0;i<len;i++){
				type = arr[i].type;
				if(!barr[type])barr[type]=[];
				barr[type].push(arr[i]);
			}
			for(type in barr){
				arr = barr[type];
				len = arr.length;
				sda.push({optgroup:'start',name:''+type+'('+len+')'});
				for(i=0;i<arr.length;i++){
					sda.push({name:''+arr[i].id+'.'+arr[i].name+'',id:arr[i].id});
				}
				sda.push({optgroup:'end'});
			}
			js.setselectdata(get('fmodeid_'+this.rand+''), sda, 'id');
		}
		
	}
	
	this.changemodeid = function(o1){
		this.fmodeid = o1.value;
		this.table.setparams({fmodeid:o1.value,key:''}, true);
	}
	
	this.onaddbefore = function(){
		if(!this.iscompany)return '新增只能在单位模式下';
		if(this.fmodeid=='0')return '请先选择模块';
		return {
			data:{'fmodeid':this.fmodeid}
		};
	}

	
	this.pipei = function(o1){
		var val = o1.innerHTML;
		js.ajax.get({
			btnobj:o1,
			url:this.getacturl('pipei'),
		},function(ret){
			o1.disabled=false;
			o1.innerHTML = val;
			js.msg('success', ret.data);
		});
	}
	
}